package net.towee.client.com.repo.view;

import java.util.ArrayList;
import java.util.List;

import net.towee.client.com.repo.presenter.RepositoryShowerPresenter.Display;
import net.towee.client.i18n.ToweeConstants;
import net.towee.client.resources.ClientResource;
import net.towee.client.widgets.SpanPanel;
import net.towee.model.repo.DocumentType;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.inject.Inject;

public class RepositoryShowerView extends FlowPanel implements Display {
	private final ClientResource resource;
	private final ToweeConstants constants;
	
	private final List<HasClickHandlers> buttonsList = new ArrayList<HasClickHandlers>();
	private final Button createNodeButton = new Button();
	private final Button cut = new Button();
	private final Button paste = new Button();
	private final Button remove = new Button();
	
	private final FlowPanel buttonsContainer = new FlowPanel();
	private final FlowPanel showerContainer = new FlowPanel();

	@Inject
	public RepositoryShowerView(ToweeConstants constants, ClientResource resource) {
		this.constants = constants;
		this.resource = resource;
		
		createButtons();
		createShowerContainer();
	}
	
	private void createShowerContainer() {
		add(showerContainer);
		showerContainer.setStyleName( resource.css().repoForShowersContainer() );
	}

	private void createButtons() {
		buttonsContainer.add(new SpanPanel( constants.add()+": " ));
		buttonsContainer.setStyleName( resource.css().repoButtonsContainer() );
		
		// Add doc create buttons
		for(DocumentType type : DocumentType.values()) {
			Button button = new Button(constants.getString("DOCTYPE_"+type.toString()));
			button.setLayoutData( type );
			button.getElement().setAttribute("document", "");
			buttonsList.add( button );
			buttonsContainer.add( button );
		}
		
		// Add tree node create button
		createNodeButton.setText( constants.addNode() );
		createNodeButton.getElement().setAttribute("node", "");
		
		buttonsContainer.add( createNodeButton );
		buttonsContainer.setVisible(false);
		add(buttonsContainer);
/*		remove.setText( constants.delete() );
		cut.setText( constants.cut() );
		paste.setText( constants.paste() );
		paste.setEnabled(false);
		
		FlowPanel opButtons = new FlowPanel();
		opButtons.getElement().getStyle().setProperty("position", "absolute");
		opButtons.getElement().getStyle().setProperty("right", "0");
		opButtons.getElement().getStyle().setProperty("top", "7px");
		opButtons.addStyleName( resource.css().repoButtonsContainer() );
		opButtons.add( createNodeButton );
		//opButtons.add( cut );
		//opButtons.add( paste );
		paste.setEnabled( true );
		buttonsContainer.add(opButtons);
	*/	
	}

	@Override
	public List<HasClickHandlers> getAddDocumentButtons() {
		return buttonsList;
	}
	
	@Override
	public HasClickHandlers getAddNodeButton() {
		return createNodeButton;
	}

	@Override
	public HasClickHandlers getRemoveNodeButton() {
		return remove;
	}

	@Override
	public HasClickHandlers getCutButton() {
		return cut;
	}

	@Override
	public HasClickHandlers getPasteButton() {
		return paste;
	}

	@Override
	public void enablePasteButton() {
		paste.setEnabled( true );
	}
	
	@Override
	public void disablePasteButton() {
		paste.setEnabled( false );
	}

	@Override
	public HasWidgets getShowerContainer() {
		return showerContainer ;
	}

	@Override
	public void showButtons() {
		buttonsContainer.setVisible(true);
	}

	@Override
	public void hideButtons() {
		buttonsContainer.setVisible(false);
	}

}
